// Created by WXX on 2021/9/24 10:41
#include <iostream>
#include <vector>
#include <unordered_set>

using namespace std;

/**
 * 执行用时：76 ms, 在所有 C++ 提交中击败了13.51%的用户
 * 内存消耗：24.9 MB, 在所有 C++ 提交中击败了25.11%的用户
 */
class Solution {
public:

    vector<vector<int>> res;
    vector<int> path;

    vector<vector<int>> findSubsequences(vector<int> &nums) {
        dfs(nums, 0);
        return res;
    }

    void dfs(vector<int> &nums, int start) {
        if (path.size() >= 2) res.push_back(path);
        if (start == nums.size()) return;

        unordered_set<int> S;
        for (int i = start; i < nums.size(); i++)
            if (path.empty() || nums[i] >= path.back()) {
                if (S.count(nums[i])) continue;  // 递归同一层不能选择之前选择过的数字
                S.insert(nums[i]);
                path.push_back(nums[i]);
                dfs(nums, i + 1);
                path.pop_back();
            }
    }
};

void OutputBasicArray2D1(vector<vector<int>> nums) {

    cout << "[";
    for (int i = 0; i < nums.size(); i++) {
        cout << "[";
        for (int j = 0; j < nums[i].size(); j++) {
            cout << nums[i][j];
            if (j != nums[i].size() - 1) cout << ", ";
        }
        cout << "]";
        if (i != nums.size() - 1) cout << ", ";
    }
    cout << "]" << endl;
}

int main() {

    vector<int> nums = {4, 6, 7, 7};
    OutputBasicArray2D1(Solution().findSubsequences(nums));

    return 0;
}
